package com.killer;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by killer on 2016/4/25.
 */
public class NavigationModeActivity extends AppCompatActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initActionBar();
    }

    private void initActionBar() {
        //得到ActionBar
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayShowHomeEnabled(true);//默认是false  默认不显示显示icon/logo
        actionBar.setDisplayUseLogoEnabled(false);

        actionBar.setLogo(R.drawable.ic_action_edit);//设置logo,默认是logo优先
        actionBar.setIcon(R.drawable.ic_launcher);
        actionBar.setTitle("主标题");
        actionBar.setSubtitle("副标题");
        actionBar.setDisplayHomeAsUpEnabled(true);//设置显示返回按钮
        actionBar.setDisplayShowTitleEnabled(true);//显示/隐藏title部分
        actionBar.setDisplayHomeAsUpEnabled(true);// 设置back按钮是否可见


         /*=============== list模式 ===============*/
    /*    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        // 初始化数据
        final List<String> objects = new ArrayList<String>();
        objects.add("主页");
        objects.add("新闻");
        objects.add("娱乐");
        //创建adapter
        ArrayAdapter<String>  adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,objects);
        //设置adapter和点击事件的处理
        actionBar.setListNavigationCallbacks(adapter, new ActionBar.OnNavigationListener() {
            @Override
            public boolean onNavigationItemSelected(int itemPosition, long itemId) {
                Toast.makeText(getApplicationContext(), "选中了 " + objects.get(itemPosition), 0).show();
                return false;
            }
        });*/

        /*=============== tab模式 ===============*/
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for (int i = 0;i<5;i++){
            ActionBar.Tab tab = actionBar.newTab();
            tab.setText("tab"+i);
            tab.setIcon(R.drawable.ic_action_call);
            tab.setTabListener(new ActionBar.TabListener() {
                @Override
                public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
                    Toast.makeText(getApplicationContext(), tab.getText()+"1111111111111", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {// 没有选中时候


                }

                @Override
                public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {// 再次选中时候
                    Toast.makeText(getApplicationContext(), tab.getText()+"1122222211111", Toast.LENGTH_SHORT).show();

                }
            });
            actionBar.addTab(tab);
        }







    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                break;
            default:
                break;
        }
        return super.onOptionsItemSelected(item);
    }





}
